<include file="Common/common" />

<body>
	<div class="layui-tab-item layui-show">
		<div class="layui-main">
			<br>
			<div class="layui-tab">
				<ul class="layui-tab-title">
					<li class="layui-this">新闻列表</li>
					<li>发布公告</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show">
						<div style="overflow-x: auto;">
							<table class="layui-table" >
								<thead>
										<tr>
											<th>公告编号</th>
											<th>标题</th>
											<th>发布时间</th>
											<th>操作</th>
										</tr> 
									</thead>
									<tbody>
										<foreach name="newsList" item="vo">
											<tr>
												<td>{$vo['id']}</td>
												<td>{$vo['title']}</td>
												<td><?php echo date('Y-m-d H:i:s',$vo['createtime']) ?></td>
												<td>
													<div class="layui-btn-group">
														<button class="layui-btn layui-btn-sm"  onclick="fun_news(this,{$vo['id']},'{$vo['title']}')">查看公告</button>
														<button class="layui-btn layui-btn-sm"  onclick="fun_delete(this,{$vo['id']},'{$vo['title']}')">删除</button>
														<if condition="$vo['top'] eq 0">
															<button class="layui-btn layui-btn-sm" lay-submit="" onclick="fun_top(this,{$vo['id']})">置顶</button>
														<else/>
															<button class="layui-btn layui-btn-sm" lay-submit="" onclick="fun_cancel(this,{$vo['id']})">取消置顶</button>
														</if>
													</div>
												</td>
											</tr>
										</foreach>
									</tbody>
							</table>
						</div>
						<div class="green-black">{$page}</div>

					</div>

					<!-- 发布公告 -->
					<div class="layui-tab-item">
						<form class="layui-form" action="">
							<div class="layui-form-item">
								<label class="layui-form-label">标题</label>
								<div class="layui-input-block">
									<input type="text" name="title" lay-verify="title|required" autocomplete="off" placeholder="请输入标题" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">内容</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入内容" lay-verify="required" name="content" class="layui-textarea"></textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">置顶</label>
								<div class="layui-input-block">
									<input type="checkbox" name="istop" lay-skin="switch" lay-text="ON|OFF">
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-input-block">
									<button class="layui-btn" lay-submit="" lay-filter="btn-news">立即发布</button>
									<button type="reset" class="layui-btn layui-btn-primary">重置</button>
								</div>
							</div>
						</form>

					</div>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	layui.use(['form'], function(){
		var form = layui.form;
		form.render();

		// 发布新闻公告
		form.on('submit(btn-news)',function (data) {
			layer.confirm('确定发布？',{offset:'none'},function(index){
				$.ajax({
		            type: "post",
		            url: "{:U('/admin.php/News/ctrl_addNews')}",
		            data: data.field,
		            dataType: "json",
		            success: function(rtJson){
		            	if (rtJson.code == 1) {
			               	setTimeout(function(){location.reload();}, 1000);
		               	}
		               	layer.msg(rtJson.msg);
		            }
		        });
			});
			return false;
		});
	});

	// 删除新闻公告
	function fun_delete(obj,id){
		layer.confirm('确定删除？',{offset:'none'},function(index){
			$.ajax({
	            type: "post",
	            url: "{:U('/admin.php/News/ctrl_deleteNews')}",
	            data: {id:id},
	            dataType: "json",
	            success: function(rtJson){
	            	if (rtJson.code == 1) {
		               	setTimeout(function(){location.reload();}, 1000);
	               	}
	               	layer.msg(rtJson.msg);
	            }
	        });
		});
	}


	// 取消置顶
	function fun_cancel(obj,id){
		layer.confirm('确定取消置顶？',{offset:'none'},function(index){
			$.ajax({
	            type: "post",
	            url: "{:U('/admin.php/News/ctrl_cancelTop')}",
	            data: {id:id},
	            dataType: "json",
	            success: function(rtJson){
	            	if (rtJson.code == 1) {
		               	setTimeout(function(){location.reload();}, 1000);
	               	}
	               	layer.msg(rtJson.msg);
	            }
	        });
		});
	}

	// 新闻公告置顶
	function fun_top(obj,id){
		layer.confirm('确定置顶？',{offset:'none'},function(index){
			$.ajax({
	            type: "post",
	            url: "{:U('/admin.php/News/ctrl_top')}",
	            data: {id:id},
	            dataType: "json",
	            success: function(rtJson){
	            	if (rtJson.code == 1) {
		               	setTimeout(function(){location.reload();}, 1000);
	               	}
	               	layer.msg(rtJson.msg);
	            }
	        });
		});

	}


	//查看新闻
	function fun_news(obj,id,name){
		layer.open({
			type: 2,
			title: name,
			shadeClose: true,
			shade: 0.8,
			scrollbar: false,
			area: ['100%', '100%'],
			content: "/admin.php/News/newsDetail?id="+id //iframe的url
		});
	}
</script>
<include file="Common/footer" />